/**
 *   递归菜单
 * @param {Array} allRouters 所有路由 项目
 * @param {Array} menuList 服务器返回的菜单/路由名字
 * @returns {Array} 递归后 的用户路由
 */

function recursionRouters(allRouters = [], menuList = []) {
  let userRoutes = [];
  //   allRouters.forEach((route) => {
  //     menuList.forEach((item) => {
  //       if (route.meta?.title === item.title) {
  //         route.meta.name = item.name;
  //         if (route.children && route.children.length) {
  //           route.children = recursionRouters(route.children, item.children);
  //         }
  //         userRoutes.push(route);
  //       }
  //     });
  //   });
  allRouters.forEach((route) => {
    menuList.forEach((item) => {
      if (route.meta?.title === item.title) {
        route.meta.name = item.name;
        if (route.children && route.children.length) {
          route.children = recursionRouters(route.children, item.children);
        }
        userRoutes.push(route);
      }
    });
  });
  //   console.log(userRoutes);s
  return userRoutes.reverse();
}
export default recursionRouters;
